package com.example.smartcity_poverty.ui.Home

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.example.smartcity_poverty.logic.Repository
import com.example.smartcity_poverty.logic.model.BannerModel
import com.example.smartcity_poverty.logic.model.MoreModel
import com.example.smartcity_poverty.logic.model.NewsModel

class HomeViewModel : ViewModel() {

    // 获取轮播图
    private val banner = MutableLiveData<Map<String, Int>>()
    val bannerList = ArrayList<BannerModel.RowsBean>()
    val bannerLiveData = Transformations.switchMap(banner){query ->
        Repository.getBanner(query)
    }
    fun setBanner(mp: Map<String, Int>){
        banner.value = mp
    }



    // 全部服务
    private val more = MutableLiveData<String>().apply {
        postValue("test")
    }
    var moreList = ArrayList<MoreModel.RowsBean>()
    val moreLiveData = Transformations.switchMap(more){
        Repository.getMore()
    }


    // 热门主题
    private val newsHot = MutableLiveData<String>().apply {
        postValue("Y")
    }
    val newsHotList = ArrayList<NewsModel.RowsBean>()
    val newsHotLiveData = Transformations.switchMap(newsHot){ query ->
        Repository.getNews(query, null)
    }

    // 热门主题
    private val news = MutableLiveData<String>()
    val newsList = ArrayList<NewsModel.RowsBean>()
    val newsLiveData = Transformations.switchMap(news){ query ->
        Repository.getNews(null, query)
    }
    fun setNewsType(type: String?){
        news.value = type
    }
}